﻿#include "FITKAbaWire.h"


namespace Interface
{
    void FITKAbaWire::getTextLabel(const int index, QString& label1, QString &label2)
    {
        FITKAbaAssEle3D2* line = this->getDataByIndex(index);
        if (line == nullptr) return;
        label1 = line->getTextLabel1();
        label2 = line->getTextLabel2();
    }

    void FITKAbaWire::getCoor(const int index, double* coor1, double* coor2)
    {
        FITKAbaAssEle3D2* line = this->getDataByIndex(index);
        if (line == nullptr) return;
        line->getCoor1(coor1);
        line->getCoor2(coor2);
    }

    bool FITKAbaWire::copy(FITKAbstractDataObject* obj)
    {
        FITKAbaWire* w = dynamic_cast<FITKAbaWire*>(obj);
        if (w == nullptr) return false;
        this->clear();
        const int n = w->getDataCount();
        for (int i=0;i<n; ++i)
        {
            FITKAbstractAbaAssemblyElement* aw = w->getDataByIndex(i);
            if(aw == nullptr) continue;
            auto anewOne = aw->getACopy();
            this->appendDataObj(anewOne);
        }
        return true;
    }

    FITKAbaAssEle3D2* FITKAbaWire::getElementByID(const int& id)
    {
        const int n = this->getDataCount();
        for (int i = 0; i < n; ++i)
        {
            FITKAbaAssEle3D2* ele = this->getDataByIndex(i);
            if(ele == nullptr) continue;
            if (ele->getElementID() == id)
                return ele;
        }
        return nullptr;
    }

    FITKAbaAssEle3D2* FITKAbaWireManager::getElementByID(const int& id)
    {
        const int n = this->getDataCount();
        for (int i = 0; i < n; ++i)
        {
            FITKAbaWire* w = this->getDataByIndex(i);
            if(w == nullptr) continue;
            FITKAbaAssEle3D2* ele = w->getElementByID(id);
            if (ele != nullptr)
                return ele;
        }
        return nullptr;
    }

}



